package com.thinkgem.jeesite.modules.oa.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.oa.dao.OaOfficicalAccountsDao;
import com.thinkgem.jeesite.modules.oa.entity.OaOfficicalAccounts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by LZY on 2018/2/24.
 */
@Service
@Transactional(readOnly = true)
public class OaOfficialAccountsService extends CrudService<OaOfficicalAccountsDao, OaOfficicalAccounts> {
    @Autowired
    private OaOfficicalAccountsDao oaOfficicalAccountsDao;

    /**
     * 比如我要查询一条数据
     * 这个是最简单的实现
     */
    public OaOfficicalAccounts getById(String id) {
        OaOfficicalAccounts oaOfficicalAccounts = oaOfficicalAccountsDao.get(id);
        //如果是重要操作就需要打log，分级别 ，debug一般本地能看到，测试环境都会屏蔽的  级别的你等下自己看下
        logger.info("查询数据");
        return oaOfficicalAccounts;
    }

    /**
     * 比如保存的数据
     * 因为这里要插入数据的所以要加事物
     *
     * @param oaOfficicalAccounts
     */
    @Transactional(readOnly = false)
    public void saveEntity(OaOfficicalAccounts oaOfficicalAccounts) {
        oaOfficicalAccountsDao.insert(oaOfficicalAccounts);
    }

    public Page<OaOfficicalAccounts> find(Page<OaOfficicalAccounts> page, OaOfficicalAccounts accounts) {

        accounts.getSqlMap().put("dsf", dataScopeFilter(accounts.getCurrentUser(), "o", "u"));

        accounts.setPage(page);
        page.setList(oaOfficicalAccountsDao.findList(accounts));

        return page;
    }

}
